﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Imaginecup.gameState.malaria.component.children
{
    public class MovePattern
    {
        private int m_Velocity;

        private List<Vector2> m_DestList = new List<Vector2>();

        private Vector2 m_MoveDir;
        private static float m_Range = 3;        

        public MovePattern()
        {
        }

    
        //목표위치에 도달했을 경우.
        public bool IsEndPattern( int currentIndex )
        {
            if (currentIndex >= m_DestList.Count)
                return true;
            return false;
        }

        //목표 방향 계산 (목표위치 도달 시 인덱스 증가후 리턴
        public int CalculateDir(Vector2 childPos , int currentIndex)
        {
            Vector2 destPos = m_DestList[currentIndex];

            float range = Vector2.Distance(childPos, destPos);

            if (range < m_Range)
            {
                currentIndex++;
            }

            m_MoveDir = Vector2.Subtract(destPos, childPos);
            m_MoveDir.Normalize();

            return currentIndex;
        }

        //목표를 향해 이동한다.
        public Vector2 GetDirection()
        {
            return m_MoveDir;
        }

        public void AddDest(Vector2 vector2)
        {
            m_DestList.Add(vector2);
        }

        public void SetVelocity(int velocity)
        {
            m_Velocity = velocity;
        }

        public int GetVelocity()
        {
            return m_Velocity;
        }



        public void Clear()
        {
            m_DestList.Clear();
        }
    }
}
